<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@include file="/context/mytags.jsp" %>
<div class="portlet box green">
    <div class="portlet-title">
        <div class="caption">
            <i class="fa fa-gift"></i>医院
        </div>
    </div>
    <div class="portlet-body form">
        <form id="hospitalDepartmentForm" class="form-horizontal form-bordered" action="/hospitalDepartment/saveHospitalDepartment" method="post">
            <div class="form-group">
                <label class="col-md-3 control-label">科室:</label>
                <div class="col-md-4">
                    <input type="hidden" id="menuIds" name="menuIds"/>
                    <ul id="menuTree" class="ztree" style="margin-top:0; width:160px;"></ul>
                </div>
            </div>
            <div class="form-actions">
                <div class="col-md-9 col-md-offset-3">
                    <button type="button" class="btn btn-primary" onclick="saveHospitalDepartment(this)">
                        <spring:message code="btn.save"></spring:message>
                    </button>
                    <button type="reset" class="btn btn-default" onclick="cancel()">
                        <spring:message code="btn.return"></spring:message>
                    </button>
                </div>
            </div>
            <input type="hidden" name="id" value="${hospitals.id}">
        </form>
    </div>
</div>
<script type="text/javascript" src="<c:url value="/static/custom/datepicker-util.js"></c:url>"></script>
<script type="text/javascript">
    $(function () {
        $('#hospitalDepartmentForm').validate();

        var setting = {
            check: {
                enable: true
            },
            data: {
                simpleData: {
                    enable: true
                }
            },
            view: {
                showIcon: false
            }
        };

        var data = ${menuList};

        $.fn.zTree.init($("#menuTree"), setting, data);

        $.fn.zTree.getZTreeObj("menuTree").expandAll(true);
    });



    // 保存医院科室信息
    function saveHospitalDepartment() {
        var nodes = $.fn.zTree.getZTreeObj("menuTree").getCheckedNodes(true);
        var menuIds = '';
        for (var i = 0; i < nodes.length; i++) {
            menuIds += nodes[i].id + ',';
        }
        $('#menuIds').val(menuIds);
        if ($('#hospitalDepartmentForm').valid()) {
            $.ajax({
                type: 'post',
                url: '<c:url value="/hospitalDepartment/saveHospitalDepartment"></c:url>',
                data: $('#hospitalDepartmentForm').serialize(),
                dataType: 'json',
                success: function (data) {
                    alert(messages[data.result]);
                    search();
                    $(".panel-search").show();
                    queryStatistics();
                }
            });
        }
    }

</script>